<template>
  <el-collapse-item name="dynamic-form">
    <template #title>
      <collapse-title title="动态表单">
        <lucide-icon name="List" />
      </collapse-title>
    </template>

    <edit-item label="表单">
      <el-select v-model="info" placeholder="请选择">
        <el-option
          v-for="item in dynamicFormList"
          :key="item.value"
          :label="item.label"
          :value="item.value"
        >
        </el-option>
      </el-select>
    </edit-item>
  </el-collapse-item>
</template>

<script>
import { getDynamicList } from "@/api/flow/work.js";
import EventEmitter from "@utils/EventEmitter";

export default {
  name: "BpmnDynamicForm",
  data() {
    return {
      dynamicFormList: [],
      info: "",
    };
  },
  mounted() {
    this.reloadDynamicFormData();
    EventEmitter.on("element-update", this.reloadDynamicFormData);
  },
  methods: {
    /** 更新动态表单数据 */
    reloadDynamicFormData() {
      this.getDynamicList();
    },
    async getDynamicList() {
      let res = await getDynamicList();
      this.dynamicFormList = res.data.map((item) => ({
        label: item.label,
        value: item.value,
      }));
    },
  },
};
</script>
